package com.lwc.cfdns.controller.admin.monitor;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lwc.cfdns.constants.ConstantsUrl;
import com.lwc.cfdns.pojo.bo.monitor.LoginLogBO;
import com.lwc.cfdns.pojo.entity.SystemLogininfor;
import com.lwc.cfdns.service.impl.SystemLogininforServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 用户登录日志
 *
 * @author luwc
 * @title LoginLogController
 * @description
 * @time 2023/7/25 09:44:01
 * @version: 1.0
 */
@RestController
@RequestMapping(ConstantsUrl.ADMIN + "/monitor")
public class LoginLogController {
    @Autowired
    private SystemLogininforServiceImpl systemLogininforService;

    /**
     * 列表
     *
     * @param loginLogBO
     * @return IPage<SystemLogininfor>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/25 09:55:54
     */
    @GetMapping("/loginlog")
    public IPage<SystemLogininfor> lists(LoginLogBO loginLogBO) {
        return systemLogininforService.lists(loginLogBO);
    }

    /**
     * 删除指定的
     *
     * @param ids
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/25 10:57:39
     */
    @DeleteMapping("/loginlog/{ids}")
    public Map<String, Object> delete(@PathVariable("ids") @NotNull(message = "Ids参数不能为空") String ids) {
        return systemLogininforService.delete(ids);
    }

    /**
     * 删除所有
     *
     * @param
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/25 10:59:01
     */
    @DeleteMapping("/loginlog/clean")
    public Map<String, Object> clean() {
        return systemLogininforService.clean();
    }

    /**
     * 解锁
     *
     * @param userName
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/25 11:01:53
     */
    @PostMapping("/loginlog/unlock/{userName}")
    public Map<String, Object> unlock(@PathVariable("userName") @NotNull(message = "要解锁的用户名不能为空") String userName) {
        return systemLogininforService.unlock(userName);
    }
}
